package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.result.Result;
import com.example.common.result.YiFeiException;
import com.example.entity.dto.LocationLabelDto;
import com.example.entity.vo.LocationLabelVo;
import com.example.entity.vo.WarehouseStockVo;
import com.example.entity.yifei.Cmsni;
import com.example.service.CmsniService;
import com.example.mapper.CmsniMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author 14501
* @description 针对表【CMSNI】的数据库操作Service实现
* @createDate 2024-08-08 08:40:00
*/
@Service
public class CmsniServiceImpl extends ServiceImpl<CmsniMapper, Cmsni> implements CmsniService{

    @Resource
    private CmsniMapper cmsniMapper;

    @Override
    public Result queryList(Integer current, Integer size,String ckbh, String code) {
        try{
            Map<String,Object> map = new HashMap<>();
            IPage<Cmsni> iPage = new Page<>(current,size);
            QueryWrapper<Cmsni> cmsniQueryWrapper = new QueryWrapper<>();
            cmsniQueryWrapper.eq("NI001",ckbh);
            if (StringUtils.isNotBlank(code)){
                cmsniQueryWrapper.like("NI002",code);
            }
            IPage<Cmsni> cmsnoIPage = this.cmsniMapper.selectPage(iPage, cmsniQueryWrapper);
            map.put("pages", cmsnoIPage.getPages());
            map.put("total", cmsnoIPage.getTotal());
            map.put("list", cmsnoIPage.getRecords());
            return Result.success(map);
        }catch (Exception e){
            throw new YiFeiException(500,"库存查询发生异常"+e.getMessage());
        }
    }





    @Override
    public List<LocationLabelVo> getLocationLabel() {
        List<LocationLabelVo> locationLabelVos = cmsniMapper.getLocationLabel();
        return locationLabelVos;
    }

    @Override
    public Result<PageInfo<WarehouseStockVo>> getWarehouseStock(LocationLabelDto locationLabelDto, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<WarehouseStockVo> list = cmsniMapper.getWarehouseStock(locationLabelDto);
        PageInfo<WarehouseStockVo> pageInfo = new PageInfo<>(list);
        return Result.ok(pageInfo);
    }
}




